
export default {
  data () {
    return {
      routesCrumb: []
    }
  },
  watch: {
    $route () {
      this.$nextTick(() => {
        this.getNowsRoute()
      })
    }
  },
  beforeMount () {
    this.$nextTick(() => {
      this.getNowsRoute()
    })
  },
  methods: {
    getNowsRoute () {
      this.allRouter = this.$router.options.routes.filter(item => item.path !== '*')[0].children
      let self = this
      this.path = []
      self.routesCrumb = []
      let routerArr = this.$route.path.split('/')
      for (let i = 0; i < routerArr.length; i++) {
        (function (i) {
          self.path = routerArr.slice(0, i + 1)
          return self.getRouteName(self.allRouter, self.path.join('/'))
        })(i)
      }
    },
    getRouteName (data, path) {
      path = path || '/'
      data && data.forEach(i => {
        if (i.path === path) {
          this.routesCrumb.push({ breadcrumbName: i.meta.title, path: i.path })
          this.allRouter = i.children ? i.children : this.allRouter
        }
      })
    }
  },
  render () {
    const { routesCrumb } = this
    return (
      <div>
        <a-breadcrumb
          routes={routesCrumb}
          {...{ scopedSlots: { ...this.$scopedSlots } }}>
          {Object.keys(this.$slots).map(name => <template slot={name}>{this.$slots[name]}</template>)}
        </a-breadcrumb>
      </div >
    )
  }
}
